package logic

import (
	"context"
	"errors"
	"short-vid-joy/models/mysql"

	"short-vid-joy/shortrpc/internal/svc"
	"short-vid-joy/shortrpc/shortrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectListLogic) CollectList(in *shortrpc.CollectListRequest) (*shortrpc.CollectListResponse, error) {
	// todo: add your logic here and delete this line

	var findUser mysql.User

	if err := findUser.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}

	var collectList []*shortrpc.CollectList

	collectList = mysql.CollectList(mysql.DB, in, collectList)

	if collectList == nil {
		return nil, errors.New("暂无收藏视频，快去收藏喜欢的视频吧～")
	}

	return &shortrpc.CollectListResponse{
		List: collectList,
	}, nil
}
